/**
 * Copyright (C) T-Systems International, 2013-2014
 *
 * The copyright of the computer program herein is the property of
 * T-Systems International. The program may be used and/or copied
 * only with the written permission of T-Systems International or in
 * accordance with the terms and conditions stipulated in the
 * agreement/contract under which the program has been supplied.
 *
 * $Author$
 * $Date$
 * $Rev$
 */
package com.tsystems.migdb.batch.validator;

import javax.validation.ConstraintViolation;
import java.util.Set;

public class ValidationMessageGenerator {

    public String generateMessage(Set<ConstraintViolation<Object>> errors) {
        StringBuilder validationMessage = new StringBuilder("Validation errors: \n");
        int i = 1;
        for (ConstraintViolation<Object> error : errors) {
            validationMessage.append(i);
            validationMessage.append(". ");
            validationMessage.append("Field name - ");
            validationMessage.append(error.getPropertyPath().toString());
            validationMessage.append(" ");
            validationMessage.append("Field value - ");
            validationMessage.append(error.getInvalidValue());
            validationMessage.append(" ");
            validationMessage.append("Error message - ");
            validationMessage.append(error.getMessage());
            validationMessage.append("\n");
            i++;
        }
        return validationMessage.toString();
    }
}
